package cn.edu.neusoft.maxingxin231.yuejian06.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;

import com.squareup.picasso.Picasso;

import java.util.List;

import cn.edu.neusoft.maxingxin231.yuejian06.Activity.ClubDetail;
import cn.edu.neusoft.maxingxin231.yuejian06.Bean.ClubBean;

public class ClubAdapter extends Base2Adapter<ClubBean> {
   String id,club_name,distance,att_num,club_address;

    public ClubAdapter(Context context, List<ClubBean> items, int layoutResource) {
        super(context, items, layoutResource);
    }


    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int position) {
        ClubBean clubBean = items.get(position);
        if(clubBean==null) return;
        final ClubViewHolder clubViewHolder = (ClubViewHolder)holder;
        final String club_id = items.get(position).getClub_id();
        final String club_name= items.get(position).getClub_name();
        final String distance = items.get(position).getDistance();
        final String att_num = items.get(position).getAtt_num();
        final String club_pic = items.get(position).getClub_pic();
        final String club_intro = items.get(position).getClub_intro();
        final String club_address = items.get(position).getClub_address();

       clubViewHolder.c_tv1.setText(club_name);
       clubViewHolder.c_tv2.setText(distance);
       Picasso.with(context).load("http://10.0.2.2:80/yuejian14/public/static/club_img/"+items.get(position).getClub_pic()).into(clubViewHolder.c_img1);

       clubViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
               //条目点击事件
               Log.i("TEST","onClick");
               Intent intent = new Intent(context,ClubDetail.class);
               intent.putExtra("id",id);
               intent.putExtra("club_id",club_id);
               intent.putExtra("club_name",club_name);
               intent.putExtra("club_pic",club_pic);
               intent.putExtra("club_intro",club_intro);
               intent.putExtra("club_address",club_address);
               context.startActivity(intent);
           }
       });

    }

    public void setList(List<ClubBean> list){
        this.items = list;
        notifyDataSetChanged();
    }
}
